#include <iostream>
#include "ThreadPoolWork.h"
#include "TCPServer.h"
#include "TCPSession.h"
#include "log4z.h"

int main()
{
	ThreadPoolWork::instance()->initialization();
	int httpServerPort = 18080;
	TCPServer<CHTTPSession> httpServer;
	httpServer.StartServer(httpServerPort);
	LOGFMTI("httpServer port:%d", httpServerPort);
	int tcpServerPort = 8080;
	TCPServer<CTCPSession> tcpServer;
	tcpServer.StartServer(tcpServerPort);
	LOGFMTI("tcpServer port:%d", tcpServerPort);
	while (1) {
#ifdef _WIN32
		Sleep(1000);
#else 
		usleep(200000);
#endif
	}
	std::cout << "Hello World!\n";
}

//#include <iostream>
//#include <vector>
//#include <string>
//#include <map>
//#include <io.h>
//
//std::map<std::string, std::string> getFilesMap(const std::string& dir) {
//	std::map<std::string, std::string> allFiles;
//
//	// Append "\\*.*" to the directory for the first search
//	std::string dir2 = dir + "\\*.*";
//
//	intptr_t handle;
//	_finddata_t findData;
//
//	handle = _findfirst(dir2.c_str(), &findData);
//	if (handle == -1) {
//		std::cout << "Can not find the file ... " << std::endl;
//		return allFiles;
//	}
//
//	do {
//		if (findData.attrib & _A_SUBDIR) { // Check if it's a subdirectory
//			// Ignore "." and ".." directories
//			if (strcmp(findData.name, ".") == 0 || strcmp(findData.name, "..") == 0)
//				continue;
//
//			// Append "\\" and the subdirectory name for the next search
//			std::string dirNew = dir + "\\" + findData.name;
//			std::map<std::string, std::string> tempFiles = getFilesMap(dirNew);
//			allFiles.insert(tempFiles.begin(), tempFiles.end());
//		}
//		else { // Not a subdirectory, i.e., it's a file
//			std::string filePath = dir + "\\" + findData.name;
//			allFiles[findData.name] = filePath;
//			//std::cout << findData.name << ": " << filePath << std::endl;
//		}
//	} while (_findnext(handle, &findData) == 0);
//	_findclose(handle); // Close the search handle
//
//	return allFiles;
//}
//
//int main() {
//	char szPath[256] = { 0 };
//	char* path = GetExeFilePaths(szPath, "web");
//	std::string directory = path;
//	std::map<std::string, std::string> filesMap = getFilesMap(directory);
//
//	// Print the map (file name -> file path)
//	for (const auto& pair : filesMap) {
//		std::cout << pair.first << ": " << pair.second << std::endl;
//	}
//
//	return 0;
//}
